package sige.cive

class PaginacaoTagLib {
    def paginacao = {attrs, body ->
        def max = Math.min(attrs.max ?: 10, 100)
        int num = attrs.total / max
        println "total = ${attrs.total}"
        println "max = $max"
        
        out << "<ul class='pagination'>"
        num.times{
            println it
            out << "<li>"
            out << g.link( action: attrs.action, 'params': [offset: it*max , 'max': max ] , "${it+1}")
            out << "</li>"
        }
        if(attrs.total%max){
            out << "<li>"
            out << g.link( action: attrs.action, "${num+1}")
            out << "</li>"
        }
        out << "</ul>"
		def field 
		out << field   
	}
}
